package UPPM;
import java.util.concurrent.TimeUnit;
import org.junit.Assert.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.*;
import java.util.List;
import org.junit.*;
import org.junit.Before;
import org.junit.After;
import com.thoughtworks.selenium.webdriven.commands.IsTextPresent;
import static org.junit.Assert.*;



public class RegisterNewUser {

	public static void main(String[] args) throws Exception {
		WebDriver driver = new FirefoxDriver();
		driver.get("http://test.unippmtest.co.uk");
		driver.manage().window().maximize();
//		WebElement createAccount = driver.findElement(By.xpath("/html/body/div[7]/div/div/div[2]/div/div/ul/li[4]/a"));
//		WebElement createAccount = driver.findElement(By.linkText("Create account"));
		WebElement createAccount = driver.findElement(By.cssSelector("html body div#randomBackground.pagebackground div#outline div.container div.header div#account-bar div#anonymous-view ul li a.navigation"));
				
		System.out.println(createAccount.getText());
		Utils.waitForElement(driver, By.xpath("/html/body/div[7]/div/div/div[2]/div/div/ul/li[4]/a"));
		
		Actions builder = new Actions(driver);
		builder.click(createAccount);
		builder.build().perform();
		createAccount.click();
				
		Utils.waitForElement(driver, By.id("registration"));
		
		WebElement clickLink = driver.findElement(By.id("registration"));
		System.out.println(clickLink.getText());
		clickLink.click();
	
		Utils.waitForElement(driver, By.id("title"));
		driver.findElement(By.id("title")).sendKeys("Mr");
		driver.findElement(By.id("firstname")).sendKeys("George");
		driver.findElement(By.id("lastname")).sendKeys("Mocanu");
		
				
		driver.findElement(By.id("emailField")).sendKeys("example124@example.com");
		driver.findElement(By.id("confirmEmailField")).sendKeys("example124@example.com");
		driver.findElement(By.id("password")).sendKeys("UMPGPassword");
		driver.findElement(By.id("confirmPassword")).sendKeys("UMPGPassword");
		driver.findElement(By.id("companyname")).sendKeys("Endava");
		driver.findElement(By.id("jobtitle")).sendKeys("Qa");
		driver.findElement(By.id("address1")).sendKeys("Cluj");
		driver.findElement(By.id("address2")).sendKeys("Cluj");
		driver.findElement(By.id("city")).sendKeys("Cluj");
		driver.findElement(By.id("postcode")).sendKeys("123432");
		
		Select droplist = new Select (driver.findElement(By.id("countrydropdown")));
		droplist.selectByVisibleText("Eire");
		
		driver.findElement(By.id("state")).sendKeys("Romania");
		driver.findElement(By.id("phonenumber")).sendKeys("12356569");
		driver.findElement(By.id("faxnumber")).sendKeys("3659899");
		driver.findElement(By.id("mobilenumber")).sendKeys("2355658");
		driver.findElement(By.id("website")).sendKeys("www.endava.com");
		driver.findElement(By.id("vatnumber")).sendKeys("252525");
		Select businessdroplist = new Select (driver.findElement(By.id("businesstypedropdown")));
		businessdroplist.selectByVisibleText("Freelance");
		
		WebElement newsletter = driver.findElement(By.id("newsletter"));
		if (!newsletter.isSelected())
			newsletter.click();
		assertTrue (newsletter.isSelected());
		
		Select howdidyoulearneddropdown = new Select (driver.findElement(By.id("howdidyoulearneddropdown")));
		howdidyoulearneddropdown.selectByVisibleText("Internet Search");
		
				
		driver.findElement(By.id("registerbutton")).click();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		
		WebElement confirmation = driver.findElement(By.xpath(".//*[@id='phcentralrow_1_phcentraltwocolumnright_1_fields']/p[1]"));
		System.out.println(confirmation.getText());
		confirmation.getText().matches("You have successfully registered. You will receive an email requesting validation of your email address.");
		driver.close();
		
	}
//		assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("You have successfully registered")); 	
//		Utils.waitForElement(driver, By.xpath(".//*[@id='pageRows']/div/div[1]/div/div[2]/div/div[2]/div/div[1]/div/h2"));
//		driver.findElement(By.xpath(".//*[@id='phcentralrow_1_phcentraltwocolumnright_1_fields']/p[1]")).getText().matches("You have successfully registered. You will receive an email requesting validation of your email address.");		
				
//		WebElement errorUl = driver.findElement(By.id("errorDiv"));
//		errorUl.getText().matches("The Email Address that has been entered is already registered.");
		
			
	
	}

